package com.ghy.controller;

import com.ghy.pojo.Headline;
import com.ghy.pojo.vo.PortalVo;
import com.ghy.service.HeadlineService;
import com.ghy.utils.JwtHelper;
import com.ghy.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("portal")
@CrossOrigin
public class PortalController {
    @Autowired
    private HeadlineService headlineService;
    @Autowired

    //查询全部
    @GetMapping("findAllTypes")
    public Result findAllTypes(){
        Result result = headlineService.findAll();
        return result;
    }

    /**
     * - 客户端向服务端发送查询关键字,新闻类别,页码数,页大小
     * - 服务端根据条件搜索分页信息,返回含页码数,页大小,总页数,总记录数,当前页数据等信息,
     *  并根据时间降序,浏览量降序排序
     * @param portalVo
     * @return
     */
    @PostMapping("findNewsPage")
    private Result findNewPage(@RequestBody PortalVo portalVo){
        Result result = headlineService.findNewPage(portalVo);
        return result;
    }

    /**
     * - 用户点击"查看全文"时,向服务端发送新闻id
     * - 后端根据新闻id查询完整新闻文章信息并返回
     * - 后端要同时让新闻的浏览量+1
     * @param hid
     * @return
     */
    @PostMapping("showHeadlineDetail")
    public Result showHeadlineDetail( Integer hid ){
        Result result = headlineService.showHeadlineDetail(hid);
        return result;
    }


}
